import { defineConfig, loadEnv } from "vite";
import path from 'path';
import react from "@vitejs/plugin-react";


//@ts-ignore
export default ({mode}) => {
    const env :Record<string , string> = loadEnv(mode , process.cwd())
    return defineConfig({
        plugins: [react()],
        resolve: {
            alias: {
                '@': path.resolve(__dirname, 'src'),
            }
        },
        // 配置代理服务器
        server: {
            port: 5005, // 开发环境启动的端口
            cors:true,
            proxy: {
                "/api": {
                    // 当遇到 /api 路径时，将其转换成 target 的值
                    target: env.VITE_APP_REAL_API,
                    changeOrigin: true,
                    rewrite: (path) => path.replace(/^\/api/, ""), // 将 /api 重写为空
                },
            },
        },
    })

}


